package itsm.isperp.module.controller.api.wechat;

import itsm.isperp.framework.core.context.ContextHolder;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;

import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.cp.api.WxCpService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2014-3-15
 * @since 1.0
 * 
 */
@Controller
@RequestMapping("api/wechat/configuration")
public class WechatConfigurationController {

	@RequestMapping("codeScan/{openid}")
	public ModelAndView saveSatisfaction(@PathVariable("openid") String openid,
			HttpServletRequest request, RedirectAttributes redirectAttributes)
			throws SQLException {
		ModelAndView mv = new ModelAndView("api/wechat/configuration/codeScan");
		WxCpService wxCpService = ContextHolder.getSpringBean("wxCpService");

		try {
			WxJsapiSignature signature = wxCpService
					.createJsapiSignature("http://zsws.qizh.com.cn/itsm/api/wechat/configuration/codeScan/" + openid);
			mv.addObject("signature", signature);
		} catch (Exception e) {
			// 错误
		}

		mv.addObject("openid", openid);
		return mv;
	}

}
